from vector import Vector

class Particle:
    '''A particle following the rules of kinematics.'''

    def __init__(self, x = 0, y = 0,
            vx = 0, vy = 0, mass = 1, attributes = []):
        self.position = Vector(x, y)
        self.velocity = Vector(vx, vy)
        self.sum_forces = Vector(0, 0)
        self.mass = mass
        # dictionary of attributes relating to one or more ForceGenerators
        # notation: '<name of generator>_<name of attribute>':<value>
        self.attributes = attributes

    def show(self):
        '''Print out the particle's attributes on the screen'''
        print("\n{0:15}{1:15}{2:15}{3:15}{4:15}{5:15}{6:15}".format(\
                self.position.x,\
                self.position.y,\
                self.velocity.x,\
                self.velocity.y,\
                self.sum_forces.x,\
                self.sum_forces.y,\
                self.mass).lstrip())

    def has_attribute(self, attribute):
        return attribute in self.attributes

    def update(self, time_since_last = 0):
        '''Do physics!'''
        # a = F / m
        # v += at
        # x += vt
        t = Vector(time_since_last, time_since_last)
        # find velocity
        acceleration = Vector(self.sum_forces.x / self.mass,
                self.sum_forces.y / self.mass)
        self.velocity += acceleration * t
        # move particle based on velocity
        self.position += self.velocity * t

